package com.example.zhangxin.myhuatuob2b.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by ZhangXin on 2016/10/12.
 */

public class HomeGoodsList {
    public static final String GOODS_ID = "goods_id";
    public static final String GOODS_NAME = "goods_name";
    public static final String GOODS_PROMOTION_PRICE = "goods_promotion_price";//促销价格
    public static final String GOODS_IMAGE = "goods_image";
    public static final String GOODS_GUIGE = "drug_spec";         //商品规格
    public static final String GOODS_FACTORY = "product_company";

    private String goods_id;
    private String goods_name;
    private String goods_promotion_price;
    private String goods_image;
    private String goods_guige;
    private String goods_factory;

    public HomeGoodsList() {
    }

    public HomeGoodsList(String goods_id, String goods_name, String goods_promotion_price, String goods_image, String goods_guige, String goods_factory) {
        this.goods_id = goods_id;
        this.goods_name = goods_name;
        this.goods_promotion_price = goods_promotion_price;
        this.goods_image = goods_image;
        this.goods_guige = goods_guige;
        this.goods_factory = goods_factory;
    }

    public static ArrayList<HomeGoodsList> newInstanceList(String json){
        ArrayList<HomeGoodsList> arrayList = new ArrayList<>();
        try {
            JSONArray array = new JSONArray(json);
            int size = null == array ? 0 : array.length();
            for (int i = 0; i < size; i++) {
                JSONObject obj = array.getJSONObject(i);
                String goods_id = obj.optString(GOODS_ID);
                String goods_name = obj.optString(GOODS_NAME);
                String goods_promotion_price = obj.optString(GOODS_PROMOTION_PRICE);
                String goods_image = obj.optString(GOODS_IMAGE);
                String goods_guige = obj.optString(GOODS_GUIGE);//规格
                String goods_factory = obj.optString(GOODS_FACTORY);//生产厂家
                arrayList.add(new HomeGoodsList(goods_id, goods_name, goods_promotion_price, goods_image, goods_guige, goods_factory));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return arrayList;
    }

    public String getGoods_id() {
        return goods_id;
    }

    public void setGoods_id(String goods_id) {
        this.goods_id = goods_id;
    }

    public String getGoods_name() {
        return goods_name;
    }

    public void setGoods_name(String goods_name) {
        this.goods_name = goods_name;
    }

    public String getGoods_promotion_price() {
        return goods_promotion_price;
    }

    public void setGoods_promotion_price(String goods_promotion_price) {
        this.goods_promotion_price = goods_promotion_price;
    }

    public String getGoods_image() {
        return goods_image;
    }

    public void setGoods_image(String goods_image) {
        this.goods_image = goods_image;
    }

    public String getGoods_guige() {
        return goods_guige;
    }

    public void setGoods_guige(String goods_guige) {
        this.goods_guige = goods_guige;
    }

    public String getGoods_factory() {
        return goods_factory;
    }

    public void setGoods_factory(String goods_factory) {
        this.goods_factory = goods_factory;
    }
}
